<?php

namespace app\common\middleware;

use app\common\model\ConfigCate;
use think\facade\Db;

class Config
{
    public function handle($request, \Closure $next)
    {
        //检测数据库配置是否为空
        $cate_list = ConfigCate::with('config')->select();
        foreach ($cate_list as $v) {
            if (count($v['config'])) {
                $config = [];
                foreach ($v['config'] as $v1) {
                    $config[$v1['key']] = $v1['value'];
                }
                \think\facade\Config::set($config, $v['alias']);
            }
        }
        return $next($request);
    }
}
